﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using Processing001.Library.Interfaces;

namespace Processing001.Library.AbstractClasses
{
    public class WorkerAbstract : IWorker
    {
        public EventHandler ResetConfiguration;
        public EventHandler DisplayGraphics;
        public EventHandler ValuesUpdate;
        protected Thread thread;

        public virtual void Start()
        {
            if (thread != null && !thread.IsAlive)
            {
                thread.Start();
            }
        }

        public virtual void Reset()
        {
            Stop();

            if (ResetConfiguration != null)
            {
                ResetConfiguration(this, EventArgs.Empty);
            }
        }

        public virtual void Stop()
        {
            if (thread != null && thread.IsAlive)
            {
                thread.Interrupt();
            }

            if (ResetConfiguration != null)
            {
                ResetConfiguration(this, EventArgs.Empty);
            }
        }
    }
}
